<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>剩余参数</title>
    <!-- 
        剩余参数语法允许我们将一个不定数量的参数表示为一个数组。
     -->
</head>

<body>

</body>
<script>
    function sum(first, ...args) {
        console.log(first); // 10
        console.log(args); // [20, 30] 
    }
    sum(10, 20, 30)
    console.log('----------------------------------------');
    // 剩余参数和解构配合使用
    let students  =['wangwu','zhangsan','lisi']
    let [s1,...s2] = students
    console.log(s1);
    console.log(s2);
    console.log('---------------------------------------');
    const sum1 = (...args) => {
        let total =0
        args.forEach(item => total+=item)
        return total
    }
   console.log( sum1(12,23,35));
   console.log('---------------------------------------');
   let arr1 = ['张三','李四','王五']
   let [s3, ...s4] = arr1
   console.log(s3);
   console.log(s4);

</script>

</html>